﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;

namespace MediaClasses
{
    public abstract class MediaBase
    {
        public string Id { get; set; }
        public string AgeRating { get; set; }
        public string Series { get; set; }
        public string Title { get; set; }
        public string OriginalTitle { get; set; }
        public string SortTitle { get; set; }
        public string Set { get; set; }
        public string Summary { get; set; }
        public string Review { get; set; }
        public string Notes { get; set; }
        public int Year { get; set; }

        public Dictionary<string, string> CustomValues { get; set; }

        public DateTime AddedTime { get; set; }
        public DateTime ReleasedTime { get; set; }

        #region File Info

        public bool IsLinked
        {
            get
            {
                bool bReturn = false;
                if (!string.IsNullOrEmpty(FilePath))
                    bReturn = true;

                return bReturn;
            }
        }
        public string FilePath { get; set; }
        public string FileName 
        {
            get
            {
                string strReturn = "";
                if (!string.IsNullOrEmpty(FilePath))
                    strReturn = System.IO.Path.GetFileNameWithoutExtension(FilePath);
                return strReturn;
            }
        }
        public string FileNameWithExtension
        {
            get
            {
                string strReturn = "";
                if (!string.IsNullOrEmpty(FilePath))
                    strReturn = System.IO.Path.GetFileName(FilePath);                
                return strReturn;
            }
        }
        public string FileDirectory
        {
            get
            {
                string strReturn = "";
                if (!string.IsNullOrEmpty(FilePath))
                    strReturn = System.IO.Path.GetDirectoryName(FilePath);
                return strReturn;
            }
        }
        public DateTime FileCreationDate
        {
            get
            {
                DateTime dtDate = new DateTime(1,1,1);
                if (!string.IsNullOrEmpty(FilePath) && System.IO.File.Exists(FilePath))
                {
                    System.IO.FileInfo fi = new System.IO.FileInfo(FilePath);
                    dtDate = fi.CreationTime;
                }
                return dtDate;
            }
        }
        public bool FileIsMissing
        {
            get
            {
                bool bReturn = false;
                if (!string.IsNullOrEmpty(FilePath) && !System.IO.File.Exists(FilePath))
                    bReturn = true;
                return bReturn;
            }
        }
        public string FileFormat { get; set; }
        public DateTime FileModifiedTime
        {
             get
            {
                DateTime dtDate = new DateTime(1,1,1);
                if (!string.IsNullOrEmpty(FilePath) && System.IO.File.Exists(FilePath))
                {
                    System.IO.FileInfo fi = new System.IO.FileInfo(FilePath);
                    dtDate = fi.LastWriteTime;
                }
                return dtDate;
            }
        }
        public long FileSize
        {
            get
            {
                long lTemp = 0;
                if (!string.IsNullOrEmpty(FilePath) && System.IO.File.Exists(FilePath))
                {
                    System.IO.FileInfo fi = new System.IO.FileInfo(FilePath);
                    lTemp = fi.Length;
                }
                return lTemp;
            }
        }

        #endregion

        public MediaBase()
        {
            Clear();
        }

        public virtual void Clear()
        {

        }

        public virtual void FromXml(XElement xelement)
        {
            //TODO: Parse all readable
        }

        public virtual XElement ToXml(string xElementName)
        {
            XElement xReturn = new XElement(xElementName);

            //TODO: Insert all writeable elements

            return xReturn;
        }
    }
}
